function addBG() {			
	maxsize = 200
	minsize = 10	
	sizediff = maxsize - minsize	
	
	spread_x = $("div#bgletters").width()
	spread_y = 500
	
	origin_x = 0
	origin_y = -10
	
	maxdistance = Math.sqrt(Math.pow(spread_x,2) + Math.pow(spread_y,2))
	
	// map random to log function
	logspread_x = Math.sqrt(spread_x)
	logspread_y = Math.sqrt(spread_y)
	
	for (i = 0; i < 50; i++) {
		// position
		logx = Math.random() * logspread_x
		logy = Math.random() * logspread_y
		x = origin_x + Math.pow(logx, 2)
		y = origin_y + Math.pow(logy, 2)
		
		// distance & size
		x2 = Math.abs(x - origin_x)
		y2 = Math.abs(y - origin_y)
		distance = Math.sqrt(Math.pow(x2, 2) + Math.pow(y2, 2))
		size = maxsize - sizediff * (distance / maxdistance) + "px"
		
		// letter & angle
		charcode = Math.floor(Math.random() * 26) + 65 // caps
		angle = Math.random() * Math.PI * 2
		
		// append letter element & style it
		letter = String.fromCharCode(charcode);
		id = "x" + i;
		bgletter = "<div id=\"" + id + "\">" + letter + "</div>"
		$("div#bgletters").append(bgletter)
		
		$("div#" + id).css("font-size", size).css("top", y).css("left", x)
		
		// although rotate works in MSIE, it messes up positioning
		if (!$.browser.msie) {
			$("div#" + id).animate({
				rotate: angle
			}, 0)
		}
	}		
}
		
function setupSubscribeForm(){
	var form = '#ajaxForm';
	var form_message = form + '-message';

	// en/disable submit button
	var disableSubmit = function(val){
		$(form + ' input[type=submit]').attr('disabled', val);
	};
	
	// setup loading message
	$(form).ajaxSend(function(){		 
		$(form_message).removeClass().addClass('sectionHeading').addClass('loading').html('Ukládám...').fadeIn();
	});
	
	// setup jQuery Plugin 'ajaxForm' 	
	var formOptions = {
		dataType:  'json',
		beforeSubmit: function(){	
			email = $("#email").val().toLowerCase();
			reader = $("#reader_type").val()
			
			isReaderKindle = /Kindle/.test(reader)			
			isReader3GKindle = /Kindle3W3G/.test(reader) || /Kindle4T3G/.test(reader)
			
			isFreeKindleEmail = /@free.kindle.com$/.test(email)
			isKindleEmail = isFreeKindleEmail || /@kindle.com$/.test(email)

			if (isReaderKindle && !isKindleEmail){
				return confirm("Vaše čtečka je Kindle, ale doručovací adresa není ukončena @kindle.com ani @free.kindle.com. Opravdu uložit?");
			}				
			if (isReader3GKindle && !isFreeKindleEmail){
				return confirm("Doručování přes 3G na adresu @kindle.com je Amazonem zpoplatněno. Pro doručování zdarma přes WiFi použijte adresu @free.kindle.com. Opravdu uložit?");								
			}							
			disableSubmit(true);
		},
		success: function(json){
			$(form_message).hide();
			if (json.type == "success"){
				$(form_message).removeClass().addClass('sectionHeading').addClass('success').html(json.message).fadeIn('slow');
			}
			else {	
				$(form_message).removeClass().addClass('sectionHeading').addClass('error').html(json.message).fadeIn('slow');
			}
			disableSubmit(false);

		},
		error: function(){			
			$(form_message).hide();
			$(form_message).removeClass().addClass('sectionHeading').addClass('error').html('Při ukládání došlo k chybě').fadeIn('slow');
			disableSubmit(false);
		}		
	};
	
	// setup jQuery Plugin 'validation'
	var validateOptions = {
		rules: { 
			reader_type: "required",
			email: { 
                required: true, 
                email: true
            }           
		},
		messages: { 
			reader_type: "Vyberte čtečku",
			email: {
				required: "Neplatný email",
				email: "Neplatný email"
			}		
		},
		// the errorPlacement has to take the table layout into account
		/*errorPlacement: function(error, element) {
			error.appendTo( element.parent().next() );
		},	*/	
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		},
		submitHandler: function(form) {
		   	$(form).ajaxSubmit(formOptions);
		}	
	}	
	
	$(form).validate(validateOptions);
}

function setupWishlistForm(){
	var form = '#ajaxForm';
	var form_message = form + '-message';

	// en/disable submit button
	var disableSubmit = function(val){
		$(form + ' input[type=submit]').attr('disabled', val);
	};
	
	// setup loading message
	$(form).ajaxSend(function(){		 
		$(form_message).removeClass().addClass('sectionHeading').addClass('loading').html('Ukládám...').fadeIn();
	});
	
	// setup jQuery Plugin 'ajaxForm' 	
	var formOptions = {
		dataType:  'json',
		beforeSubmit: function(){										
			disableSubmit(true);
		},
		success: function(json){
			$(form_message).hide();
			if (json.type == "success"){
				$(form_message).removeClass().addClass('sectionHeading').addClass('success').html(json.message).fadeIn('slow');
			}
			else {	
				$(form_message).removeClass().addClass('sectionHeading').addClass('error').html(json.message).fadeIn('slow');
			}
			disableSubmit(false);

		},
		error: function(){			
			$(form_message).hide();
			$(form_message).removeClass().addClass('sectionHeading').addClass('error').html('Při ukládání došlo k chybě').fadeIn('slow');
			disableSubmit(false);
		}		
	};
	
	// setup jQuery Plugin 'validation'
	var validateOptions = {
		rules: { 	
			name: "required",
			homepage: { 
				required: true,
                url: true
            },
			contact: {                 
                email: true
            }           
		},
		messages: { 
			name : {
				required: "Zadejte jméno webu"
			},
			homepage: { 
				required: "Zadejte link",
				url: "Neplatné URL"
			}, 
			contact: {				
				email: "Neplatný email"
			}		
		},		
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		},
		submitHandler: function(form) {
		   	$(form).ajaxSubmit(formOptions);
		}	
	}	
	
	$(form).validate(validateOptions);
}